package CorporateInterview;

/**
 * [x,a,b,n],初始精力为x，学习一小时精力减少a，休息一小时精力增加b，n小时能获得多少知识量
 * study m hour->x = x-ma,knowlege+=mx, n= n-m
 * sleep k hour->x = x+kb , n=n-k
 * n->study/sleep->n-1,
 */
public class MT2 {
    int max;
    private void dfs(int x, int a, int b,int n){
        if (n==0) {
            max = Math.max(x,max);
            return;
        }
        if (x<=0) dfs(x+b,a,b,n-1);
        if (x>=a){
            dfs(x+b,a,b,n-1); //休息
            dfs(x-a,a,b,n-1); //学习
        }
    }

    public static void main(String[] args) {
        MT2 mt2 = new MT2();
        mt2.dfs(10,5,5,3);
        System.out.println(mt2.max);

    }


}
